package leecoke;

public class Test523 {
    public static void main(String[] args) {
        int[] nums = {23,2,4,6,6};
//        int[] nums = {0,0};
        int k = 7;
        System.out.println(checkSubarraySum(nums, k));
    }

    public static boolean checkSubarraySum(int[] nums, int k) {
        if (nums == null || nums.length < 2) {
            return false;
        }
        int len = nums.length;
        int[] preSum = new int[len + 1];
        for (int i = 1; i < len + 1; i++) {
            preSum[i] = nums[i - 1] + preSum[i - 1];
        }
        // i 控制前缀和
        for (int i = 1; i < len + 1; i++) {
            for (int j = 0; j < i; j++) {
                if (((preSum[i] - preSum[j]) == 0 || (preSum[i] - preSum[j]) % k == 0) && i - j > 1) {
                    return true;
                }
            }
        }

        return false;
    }
}
